<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\GkyMsgUser;

/**
 * GkyMsgUserSearch represents the model behind the search form about `app\models\GkyMsgUser`.
 */
class GkyMsgUserSearch extends GkyMsgUser
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'msgid', 'isread', 'readtime', 'iscollect'], 'integer'],
            [['userid'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = GkyMsgUser::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            //分页
            'pagination' => [
                'pageSize' => 10,
            ],
            //排序
            'sort'=>[
                'defaultOrder'=>[
                    'id'=>SORT_ASC,
                ]
            ]
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'msgid' => $this->msgid,
            'isread' => $this->isread,
            'readtime' => $this->readtime,
            'iscollect' => $this->iscollect,
        ]);

        $query->andFilterWhere(['like', 'userid', $this->userid]);

        return $dataProvider;
    }
}
